<?php

class User_access extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {
            redirect('user_login/user', 'refresh');
        }

        $this->load->model('user');
        $this->load->model('user_role');
        $this->load->helper('user_helper');
        $this->load->library('user_id');

        if ($this->cek() == 0) {
            redirect('user_login/user', 'refresh');
        }
    }

    function index() {
        $data['id'] = $this->user_id->id();

        $data['access'] = $this->user_role->access($this->cek());
        $data['i'] = 1;
        $data['rows'] = $this->user->index();
        $data['content'] = 'user_acess/index';
        $this->load->view('template/user', $data);
    }

    function edit() {
        $data['id'] = $this->user_id->id();

        $id_access = $this->uri->segment(3);
        $data['id_access'] = $id_access;
        $data['access'] = $this->user_role->access($this->cek());
        $data['rows'] = $this->user_role->edit($id_access);
        $data['content'] = 'user_acess/edit';
        $this->load->view('template/user', $data);
    }

    function update() {
        $id_access = $this->input->post('id_access', TRUE);

        $booking_m = $this->input->post('booking_m', TRUE);
        $booking_m_delete = $this->input->post('booking_m_delete', TRUE);
        $booking_m_confirm = $this->input->post('booking_m_confirm', TRUE);

        $bank = $this->input->post('bank', TRUE);
        $bank_add = $this->input->post('bank_add', TRUE);
        $bank_edit = $this->input->post('bank_edit', TRUE);
        $bank_delete = $this->input->post('bank_delete', TRUE);
        $deposit = $this->input->post('deposit', TRUE);
        $deposit_edit = $this->input->post('deposit_edit', TRUE);
        $deposit_delete = $this->input->post('deposit_delete', TRUE);
        $document = $this->input->post('document', TRUE);
        $document_add = $this->input->post('document_add', TRUE);
        $document_edit = $this->input->post('document_edit', TRUE);
        $document_delete = $this->input->post('document_delete', TRUE);
        $list_pelanggan = $this->input->post('list_pelanggan', TRUE);
        $list_edit = $this->input->post('list_edit', TRUE);
        $list_delete = $this->input->post('list_delete', TRUE);

        $manajemen_konten = $this->input->post('manajemen_konten', TRUE);
        $notifikasi_email = $this->input->post('notifikasi_email', TRUE);
        $jadwal_p = $this->input->post('jadwal_p', TRUE);

        $news_add = $this->input->post('news_add', TRUE);
        $news = $this->input->post('news', TRUE);
        $news_edit = $this->input->post('news_edit', TRUE);
        $news_delete = $this->input->post('news_delete', TRUE);
        $ym = $this->input->post('ym', TRUE);
        $ym_edit = $this->input->post('ym_edit', TRUE);
        $ym_delete = $this->input->post('ym_delete', TRUE);
        $user_access = $this->input->post('user_access', TRUE);
        $user_access_add = $this->input->post('user_access_add', TRUE);
        $user_access_edit = $this->input->post('user_access_edit', TRUE);
        $user_access_delete = $this->input->post('user_access_delete', TRUE);
        
        
        $data = array(
            'booking_m' => $booking_m,
            'booking_m_delete' => $booking_m_delete,
            'booking_m_confirm' => $booking_m_confirm,
            'bank' => $bank,
            'bank_add' => $bank_add,
            'bank_edit' => $bank_edit,
            'bank_delete' => $bank_delete,
            'deposit' => $deposit,
            'deposit_edit' => $deposit_edit,
            'deposit_delete' => $deposit_delete,
            'document' => $document,
            'document_add' => $document_add,
            'document_edit' => $document_edit,
            'document_delete' => $document_delete,
            'jadwal_p' => $jadwal_p,
            'list_pelanggan' => $list_pelanggan,
            'list_edit' => $list_edit,
            'list_delete' => $list_delete,
            'manajemen_konten' => $manajemen_konten,
            'notifikasi_email' => $notifikasi_email,
            'news_add' => $news_add,
            'news_edit' => $news_edit,
            'news_delete' => $news_delete,
            'ym' => $ym,
            'ym_edit' => $ym_edit,
            'ym_delete' => $ym_delete,
            'user_access' => $user_access,
            'user_access_add' => $user_access_add,
            'user_access_edit' => $user_access_edit,
            'user_access_delete' => $user_access_delete,
        );
        
        
        $this->user_role->update($id_access, $data);
    }

    function id() {
        $session_data = $this->session->userdata('logged_in');
        return $session_data['id'];
    }

    function cek() {
        $level = $this->user->cek($this->id());
        if ($level) {
            $level;
        } else {
            $level = 0;
        }
        return $level;
    }

}

?>
